#include "Object3D.h"

Object3D::Object3D( )
{
	D3DXMatrixIdentity( &matrix );
}

Object3D::~Object3D( )
{
}

void Object3D::translate( float x, float y, float z )
{
	D3DXMATRIX tmp;
	D3DXMatrixMultiply( &matrix, &matrix, D3DXMatrixTranslation( &tmp, x, y, z ) );
}

void Object3D::scale( float sx, float sy, float sz )
{
	D3DXMATRIX tmp;
	
	float dx = matrix._41;
	float dy = matrix._42;
	float dz = matrix._43;
	
	matrix._41 = 0.0f;
	matrix._42 = 0.0f;
	matrix._43 = 0.0f;

	D3DXMatrixMultiply( &matrix, &matrix, D3DXMatrixScaling( &tmp, sx, sy, sz ) );

	matrix._41 = dx;
	matrix._42 = dy;
	matrix._43 = dz;
}

void Object3D::rotate( float x, float y, float z )
{
	D3DXMATRIX tmp;
	
	float dx = matrix._41;
	float dy = matrix._42;
	float dz = matrix._43;
	
	matrix._41 = 0.0f;
	matrix._42 = 0.0f;
	matrix._43 = 0.0f;

	if ( x ) D3DXMatrixMultiply( &matrix, &matrix, D3DXMatrixRotationX( &tmp, x ) );
	if ( y ) D3DXMatrixMultiply( &matrix, &matrix, D3DXMatrixRotationY( &tmp, y ) );
	if ( z ) D3DXMatrixMultiply( &matrix, &matrix, D3DXMatrixRotationZ( &tmp, z ) );

	matrix._41 = dx;
	matrix._42 = dy;
	matrix._43 = dz;
}